package com.atguigu.gulimall.order.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.utils.UserAuthUtils;
import com.atguigu.gulimall.order.biz.OrderBizService;
import com.atguigu.gulimall.order.entity.OrderInfo;
import com.atguigu.gulimall.order.vo.OrderConfirmVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author nicc
 * @version 1.0
 * @className OrderRpcController
 * @date 2022-10-20 11:46
 */
@RequestMapping("/api/inner/order")
@RestController
public class OrderRpcController {

    @Autowired
    private OrderBizService orderBizService;

    /**
     * 提交秒杀单
     * @param orderInfo
     * @return
     */
    @PostMapping("/seckillorder/submit")
    public Result<String> saveSeckillOrder(@RequestBody OrderInfo orderInfo){

        Long orderId = orderBizService.saveSeckillOrder(orderInfo);
        return Result.ok(orderId.toString());
    }

    /**
     * 返回指定订单数据
     * @param orderId
     * @return
     */
    @GetMapping("/info/{orderId}")
    public Result<OrderInfo> getOrderInfoData(@PathVariable("orderId") Long orderId){

        Long userId = UserAuthUtils.getUserAuthInfo().getUserId();

        //根据订单id查询订单数据
        OrderInfo orderInfo = orderBizService.getOrderInfoData(orderId, userId);

        return Result.ok(orderInfo);
    }

    /**
     * 获取订单确认页数据
     * @return
     */
    @GetMapping("/confirm/data")
    public Result<OrderConfirmVo> getOrderConfirmData(){

        OrderConfirmVo confirmVo = orderBizService.getOrderConfirmData();
        return Result.ok(confirmVo);
    }
}
